<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>现货供应列表</title>
		<jsp:include page="../lbi/css.jsp"></jsp:include>
        <link rel="stylesheet" href="<c:url value="/static/layui/css/layui.css"/>" /> 
        <link rel="stylesheet" href="<c:url value="/static/css/supply_list.css"/>" /> 
	</head>
	<body>
		<div class="wrap">
			<!-- 头部开始-->
			<jsp:include page="../lbi/head.jsp"></jsp:include>
			<!-- 头部结束 -->
			<div class="nav_bottom common"></div>
			<!--内容开始-->
			<div class="content common">
				<div class="selector" id="s_list">
				
				    <div class="selector-list hy-list clearfix">
                        <div class="list-name hy-list-name fl">
                            <span>行业分类 ：&nbsp;&nbsp;</span>
                        </div>
                        <ul class="list-ul hy-list-ul fl ">
                            <li class="fl active">
                                <a href="#" onclick="s_doPage('不限-1','','');"> 不限 </a>
                            </li>
                            <c:forEach items="${category }" var="category">
                                <li class="fl">
                                    <a href="#" class="" onclick="s_doPage('${category.categoryId}','','');">${category.name }</a>
                                </li>
                            </c:forEach>
                        </ul>
                    </div>
                    <div class="selector-list area-list clearfix">
                        <div class="list-name area-list-name fl">
                            <span>所属地区 ：&nbsp;&nbsp;</span>
                        </div>
                        <ul class="list-ul area-list-ul fl ">
                            <li class="fl active">
                                <a href="#" onclick="s_doPage('','不限-1','');"> 不限 </a>
                            </li>
                            
                            <c:forEach items="${sysarea }" var="sysarea">
                                <li class="fl">
                                <a href="#" onclick="s_doPage('','${sysarea.areaCode}','');">${sysarea.name }</a>
                                </li>
                            </c:forEach>
                        </ul>
                    </div>
                    <div class="selector-list mes-list clearfix">
                        <div class="list-name mes-list-name fl">
                            <span>信息类别：&nbsp;&nbsp;</span>
                        </div>
                            <ul class="list-ul mes-list-ul fl ">
            
                                <li class="fl active">
                                    <a href="#" onclick="s_doPage('','','1');"> 供应 </a>
                                </li>
            
                                <li class="fl">
                                    <a href="#" onclick="s_doPage('','','2');">求购</a>
                                </li>
                            </ul>
                    </div>
                </div>
                
				<div class="filter clearfix">
					<div class="zzgy fl">正在供应</div>
					<div class="fb-btn fl">
						<a class="qg-btn" href="#" >发布求购</a>
						<a class="gy-btn" href="#" >发布供应</a>
					</div>
					<div class="f-page fr">
						<a class="fp-prev fl" onclick="changeNum(this,'1')"> ＜ </a>
						<span class="fp-text">
			               <b class="cur-num selected-color">3</b><em>&nbsp;/&nbsp;</em><i class="total-num">10</i>
			           </span>
			           <a class="fp-next fr" onclick="changeNum(this,'3')"> ＞  </a>
					</div>
				</div> 
				 
				<div class="product-content  clearfix" id="supply_list">
			    </div> 
			
			    <div class="page">
			    	<div class="tc" id="pagination"></div>
			    </div>
				
				<div class="ad"><img src="static/img/ad.png"/></div>
				
				<div class="company-enter">
					<h3>已入驻企业</h3>
					<ul class="clearfix">
						<li>
							<img src="static/img/rz00.png"/>
						</li>
						<li>
							<img src="static/img/rz01.png"/>
						</li>
						<li>
							<img src="static/img/rz02.png"/>
						</li>
						<li>
							<img src="static/img/rz00.png"/>
						</li>
						<li>
							<img src="static/img/rz01.png"/>
						</li>
					</ul>
				</div>
			</div>
			<!--内容结束-->
			<footer class="common">
				<div class="footer-top">
					<ul>
						<li class="plqq">
							<span class="icon"></span>
							<h1>品种规格齐全</h1>
						</li>
						<li class="zzbz">
							<span class="icon"></span>
							<h1>质量可靠保障</h1>
						</li>
						<li class="jgyz">
							<span class="icon"></span>
							<h1>价格占有优势</h1>
						</li>
						<li class="qqbt">
							<span class="icon"></span>
							<h1>缺钱可打白条</h1>
						</li>
						<li class="mfzc">
							<span class="icon"></span>
							<h1>免费找货找车</h1>
						</li>
					</ul>
				</div>
				<div class="footer-bottom">
					<h1 class="common tc">Copyright©right;2018 www.zaishengwang.com Inc. All rights reserved</h1>
					<h2 class="common tc">苏ICP证161025号 | 苏ICP备15001001号 | 再生网</h2>
				</div>
			</footer>

		</div>
		<input type="hidden" id="c_id" value="" />
        <input type="text" id="province_id" value="" />
        <input type="text" id="type_id"     value="" />
		<script type="text/javascript" src="<c:url value="/static/layui/layui.all.js"/>"></script>
		<script type="text/javascript">
			
			    //增加数量    
			    function changeNum(obj,type)
			    {
			        var numInput = $('.cur-num');console.log(numInput);
			        var num = parseInt(numInput.html());console.log(num);
			        var stock = parseInt($('.total-num').html());console.log(stock);
			        if(type == 1){num--;}
			        if(type == 3){num++;}
			        if(num <=0 ){num=1;}
			        if(num>=stock){num=stock;}
			        numInput.html(num);
			        /^[0-9]*$/.test(num)?num = num:num =1;
			        if(num==1){ 
			            $('.fp-prev').addClass('disabled');
			        }else if(num==stock){
			            $('.fp-next').addClass('disabled');
			        }else{
			            $('.fp-prev').removeClass('disabled');
			            $('.fp-next').removeClass('disabled');
			        }
			    }
			    //var currPage = 1;
                $(document).ready(function(){
                	//导航高亮
    	        	$("#nav_main li").eq(2).addClass("selected-color");
                    $('.list-ul li').click(function() {
	                    //选项卡按钮样式切换
	                    $(this).parent(".list-ul").children("li").removeClass('active');
	                    $(this).addClass('active');
                    });
                    
                    s_doPage("","","1");
                })
			   
                function s_doPage(categoryId,province,type){
                	
                	getRequest = GetRequest();
                	currPage = getRequest.currPage;
                    
                    if (currPage == undefined) {
                    	currPage = 1
                    }
                    
                    if (categoryId == undefined || categoryId == "") {
                        categoryId = $("#c_id").val()
                    }else if (categoryId == "不限-1") {
                        categoryId = "";
                        $("#c_id").val("");
                    }else {
                        $("#c_id").val(categoryId);
                    }
                    if (province == undefined || province == "") {
                        province = $("#province_id").val()
                    }else if (province == "不限-1") {
                        province = "";
                        $("#province_id").val("");
                    }else {
                        $("#province_id").val(province)
                    }
                    
                	if(type == undefined || type == ""){
                		type = $("#type_id").val()
                	}else{
                		$("#type_id").val(type)
                	} 
                    
                    $("#c_"+categoryId).addClass('active').siblings().removeClass("active");
                    $("#s_"+province).addClass('active').siblings().removeClass("active");
                    $("#t_"+type).addClass('active').siblings().removeClass("active"); 
                    
                    if (categoryId == "不限") {
                    	categoryId = "";
                    }
                    
                    if (province == "不限") {
                    	province = "";
                    }
                     if (type ==  "求购"){
                    	type = "";
                    } 
                    	
                	$.ajax({
                        type: "post",
                        url: "<c:url value="/goodssupplyList.do"/>",
                        data: {
                        	categoryId : categoryId,
                            province : province,
                            type : type,
                            page : currPage,
                            size : 10
                        },
                        cache:false,
                        async:false,
                        dataType: "json",
                        success: function(data){
                        	 var result = "";
                             
                             if (data.goodssupplyVo.result.length>0) {
                                 for (var i = 0 ; i<data.goodssupplyVo.result.length;i++) {
                                	 result += '<div class="product-list">';
                                	 result += '<div class="product-list-l fl">';
                                	 result += "<a href=\"<c:url value="/goodsSupplydetails.do"/>?id="+data.goodssupplyVo.result[i].bId+"\"><img src=\"static/img/item00.png\"></a>";
                                	 result += '</div>';
                                     result += '<div  class="product-list-r fl">';
                                     result += '<h1 class="p-title">'+data.goodssupplyVo.result[i].title+'</h1>';
                                     result += '<ul class="clearfix">';
                                     result += '<li>数量：'+data.goodssupplyVo.result[i].num+''+data.goodssupplyVo.result[i].company+'吨</li>';
                                     result += '<li>目标价格：'+data.goodssupplyVo.result[i].price+'元</li>';
                                     result += '<li>地区：'+data.goodssupplyVo.result[i].provinceName+'</li>';
                                     result += '<li>已有报价：<span class="warn-color"> '+data.goodssupplyVo.result[i].priceNum+' </span> 条</li>';
                                     result += '<li>发布日期：'+data.goodssupplyVo.result[i].createTime.substring(0, 10)+'</li>';
                                     result += '<li>剩余时间：还剩  '+data.goodssupplyVo.result[i].deadline+'/天</li>';
                                     result += '<li style="width:100%;">卖家：'+data.goodssupplyVo.result[i].userName+'</li>';
                                     result += '</ul>';
                                     result += "<a class=\"price-btn\" href=\"<c:url value="/goodsSupplyoffer.do"/>?id="+data.goodssupplyVo.result[i].bId+"\">立即报价</a>";
                                    // result += "<a class="price-btn" href=\"<c:url value="/supplyDemanDetail.do"/>立即报价</a>";
                                     result += '</div>';
                                     result += '</div>'
                                     }
                             }
                            
                            $("#supply_list").html(result);
                            
                            paged(currPage,10,data.goodssupplyVo.total);
                        }
                	})
                }
                
                
                function paged(currPage,size,pageCount){
                    //分页效果
                    layui.use(['laypage', 'layer'], function() {
	                    var laypage = layui.laypage,
	                        layer = layui.layer;
	
	                    //完整功能
	                    laypage.render({
	                        elem: 'pagination',
	                        count: pageCount,//数据总数
	                        limit:size,//每页显示数据
	                        curr:currPage,
	                        layout: [ 'prev', 'page', 'next','count', 'limit', 'refresh', 'skip'],
	                        jump: function(obj,first) {
	                            currPage =obj.curr;
	                            if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr  ajax 再次请求
	                              window.location.href = '?currPage='+ obj.curr; 
	                            }
	                        }
	                    });
	                 }) 
                };
                
                function GetRequest() {
                    var url = location.search; //获取url中"?"符后的字串
                    var theRequest = new Object();
                    if(url.indexOf("?") != -1) {
                        var str = url.substr(1);
                        strs = str.split("&");
                        for(var i = 0; i < strs.length; i++) {
                            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                        }
                    }
                    return theRequest;
                }
			
		</script>
	</body>
</html>
